//
//


#include "GetPhotoByWed.h"

/////////////////
//CGetPhotoByWed
CGetPhotoByWed::GetPhotoByWed()
{
	m_p_session = NULL;
	m_timeout = 0;
	m_use_proxy = false;
	m_info_status_code = 0;
	in_file = NULL;
	out_file = NULL;
}

CGetPhotoByWed::~GetPhotoByWed()
{
	Close();
}

BOOL CGetPhotoByWed::initialise(LPCSTR agent_name /*=NULL*/)
{
	Close();
	m_info_status_code = 0;
	m_p_session = new CWebGrabSession(agent_name);

	if (m_timeout != 0) {
		m_p_session->SetOption(INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, m_timeout);
	}
	
	if (m_use_proxy) {
		char buf[10];
		itoa(m_port, buf, 10);
		CString tmp = m_proxy + ":" + (CString) buf;
		INTERNET_PROXY_INFO proxy_info;
		proxy_info.lpszProxy = tmp;
		proxy_info.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
		proxy_info.lpszProxyBypass = NULL;
		m_pSession->SetOption(INTERNET_OPTION_PROXY, (LPCOID)&proxy_info, sizeof(INTERNET_OPTION_PROXY));
	}

	return (m_p_session != NULL)

}

void CGetPhotoByWed::Close()
{
	if (m_p_session) {
		m_p_session->Close();
		delete m_p_session;
	}
	m_p_session = NULL;
	CloseFile();
}

CString CGetPhotoByWed::GetErrorMessage()
{
	return m_p_session->GetErrorMessage();
}

void CGetPhotoByWed::SetTimeOut(DWORD time_out)
{
	m_timeout = time_out;
}

double CGetPhotoByWed::GetRate()
{
	return m_transfer_rate;
}

void CGetPhotoByWed::SetProxyServer(LPCSTR server)
{
	m_proxy = server;
}

void CGetPhotoByWed::SetProxyPort(UINT port)
{
	m_potr = port;
}

void CGetPhotoByWed::SetUseProxy(bool use)
{
	m_use_proxy = use;
}

void CGetPhotoByWed::SetProxy(LPCSTR proxy, WORD port, bool useProxy)
{
	SetProxyServer(proxy);
	SetProxyPort(port);
	SetUseProxy(useProxy);
}

SHORT CGetPhotoByWed::GetErrorCode()
{
	return (!m_error_message.IsEmpty()); //just for now say...
}

BOOL CGetPhotoByWed::GetFile()
{
}

DWORD CGetPhotoByWed::GetPageStatusCode()
{
	return m_info_status_code;
}

CStirng CGetPhotoByWed::GetRawHeaders()
{
	return m_rew_headers;
}

/////////////////
//CWebGrabSession

CWebGrabSession::CWebGrabSession(LPCTSTR szAgentName) : CInternetSession(szAgentName)
{
	CommonConstruct();
}

CWebGrabSession::~CWebGrabSession()
{
}

void CWedGrabSession::CommonConstruct()
{
	
}











